package com.ruoyi.system.util;

import com.ruoyi.system.domain.DesignSchemeImage;
import com.ruoyi.system.entity.ContractFile;
import com.ruoyi.system.vo.MsgAttachmentVO;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息附件转换工具类
 * 用于将不同类型的附件转换为统一的MsgAttachmentVO格式
 * 
 * @author ruoyi
 * @since 2024-01-01
 */
public class MsgAttachmentConverter {

    /**
     * 将设计图片转换为通用附件格式
     * 
     * @param designImages 设计图片列表
     * @return 通用附件列表
     */
    public static List<MsgAttachmentVO> convertDesignImages(List<DesignSchemeImage> designImages) {
        List<MsgAttachmentVO> attachments = new ArrayList<>();
        if (designImages != null) {
            for (DesignSchemeImage image : designImages) {
                MsgAttachmentVO attachment = new MsgAttachmentVO();
                attachment.setId(image.getId());
                attachment.setFileName(image.getFileName());
                attachment.setOriginalName(image.getFileName());
                attachment.setFileType(image.getFileType());
                attachment.setFileSize(image.getFileSize());
                attachment.setFilePath(image.getFilePath());
                attachment.setDownloadUrl(image.getFilePath()); // 设计图片的filePath就是下载地址
                attachment.setBusinessType(1); // 1-设计图片
                attachment.setSpaceType(image.getSpaceType());
                attachment.setSortOrder(image.getSortOrder());
                attachment.setCreateTime(image.getCreatedTime() != null ? image.getCreatedTime().toString() : null);
                attachments.add(attachment);
            }
        }
        return attachments;
    }

    /**
     * 将合同附件转换为通用附件格式
     * 
     * @param contractFiles 合同附件列表
     * @return 通用附件列表
     */
    public static List<MsgAttachmentVO> convertContractFiles(List<ContractFile> contractFiles) {
        List<MsgAttachmentVO> attachments = new ArrayList<>();
        if (contractFiles != null) {
            for (ContractFile contractFile : contractFiles) {
                MsgAttachmentVO attachment = new MsgAttachmentVO();
                attachment.setId(contractFile.getId());
                attachment.setFileName(contractFile.getFileName());
                attachment.setOriginalName(contractFile.getOriginalName());
                attachment.setFileType(contractFile.getFileType());
                attachment.setFileSize(contractFile.getFileSize());
                attachment.setDownloadUrl(contractFile.getDownloadUrl());
                attachment.setBusinessType(contractFile.getBusinessType()); // 使用合同附件的业务类型
                attachment.setCreateTime(contractFile.getCreateTime() != null ? contractFile.getCreateTime().toString() : null);
                attachments.add(attachment);
            }
        }
        return attachments;
    }
}
